(in-package :graph-model)

(defgeneric node-out-arcs (node)
  (:documentation "out-going arcs of node"))

(defclass node (num-mixin marked-mixin label-mixin weight-mixin)
  ((out-arcs
    :initform nil
    :initarg :out-arcs
    :accessor node-out-arcs)))

(defmethod print-object ((node node) stream)
  (format stream "~A~:[~;[~A]~]"
	  (num node)
	  (weight node)
	  (weight node)))

(defun make-labeled-node (num &optional (label nil))
  (make-instance 'node :num num :label label))

(defun make-node (num)
  (make-labeled-node num))

;;; nodes in a graph should be eq-comparable
(defmethod node-member ((node node) (nodes list))
  (member node nodes :test #'eq))

(defmethod node-remove ((node node) (nodes list))
  (remove node nodes :test #'eq))

(defmethod node-adjoin ((node node) (nodes list))
  (adjoin node nodes :test #'eq))

(defmethod node-union ((nodes1 list) (nodes2 list))
  (union nodes1 nodes2 :test #'eq))

(defmethod node-delete-duplicates ((nodes list))
  (delete-duplicates nodes :test #'eq))

(defmethod node-remove-duplicates ((nodes list))
  (remove-duplicates nodes :test #'eq))

(defmethod node-set-difference ((nodes1 list) (nodes2 list))
  (set-difference nodes1 nodes2 :test #'eq))

(defmethod node-subsetp ((nodes1 list) (nodes2 list))
  (subsetp nodes1 nodes2 :test #'eq))


;;;
(defmethod mark-node ((n node))
  (mark-object n))
(defmethod mark-nodes-list ((n list))
  (dolist (node n) (mark-node node)))